package com.bcmusic.point.controller;

import com.bcmusic.point.pojo.WholeAsset;
import com.bcmusic.point.service.WholeAssetService;
import com.github.pagehelper.PageInfo;
import entity.Result;
import entity.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/****
 * @Author:admin
 * @Description:
 * @Date 2019/6/14 0:18
 *****/

@RestController
@RequestMapping("/wholeAsset")
@CrossOrigin
public class WholeAssetController {

    @Autowired
    private WholeAssetService wholeAssetService;

    /***
     * WholeAsset分页条件搜索实现
     * @param wholeAsset
     * @param page
     * @param size
     * @return
     */
    @PostMapping(value = "/search/{page}/{size}" )
    public Result<PageInfo> findPage(@RequestBody(required = false)  WholeAsset wholeAsset, @PathVariable  int page, @PathVariable  int size){
        //调用WholeAssetService实现分页条件查询WholeAsset
        PageInfo<WholeAsset> pageInfo = wholeAssetService.findPage(wholeAsset, page, size);
        return new Result(true,StatusCode.OK,"查询成功",pageInfo);
    }

    /***
     * WholeAsset分页搜索实现
     * @param page:当前页
     * @param size:每页显示多少条
     * @return
     */
    @GetMapping(value = "/search/{page}/{size}" )
    public Result<PageInfo> findPage(@PathVariable  int page, @PathVariable  int size){
        //调用WholeAssetService实现分页查询WholeAsset
        PageInfo<WholeAsset> pageInfo = wholeAssetService.findPage(page, size);
        return new Result<PageInfo>(true,StatusCode.OK,"查询成功",pageInfo);
    }

    /***
     * 多条件搜索品牌数据
     * @param wholeAsset
     * @return
     */
    @PostMapping(value = "/search" )
    public Result<List<WholeAsset>> findList(@RequestBody(required = false)  WholeAsset wholeAsset){
        //调用WholeAssetService实现条件查询WholeAsset
        List<WholeAsset> list = wholeAssetService.findList(wholeAsset);
        return new Result<List<WholeAsset>>(true,StatusCode.OK,"查询成功",list);
    }

    /***
     * 根据ID删除品牌数据
     * @param id
     * @return
     */
    @DeleteMapping(value = "/{id}" )
    public Result delete(@PathVariable Long id){
        //调用WholeAssetService实现根据主键删除
        wholeAssetService.delete(id);
        return new Result(true,StatusCode.OK,"删除成功");
    }

    /***
     * 修改WholeAsset数据
     * @param wholeAsset
     * @param id
     * @return
     */
    @PutMapping(value="/{id}")
    public Result update(@RequestBody  WholeAsset wholeAsset,@PathVariable Long id){
        //设置主键值
        wholeAsset.setAssetId(id);
        //调用WholeAssetService实现修改WholeAsset
        wholeAssetService.update(wholeAsset);
        return new Result(true,StatusCode.OK,"修改成功");
    }

    /***
     * 新增WholeAsset数据
     * @param wholeAsset
     * @return
     */
    @PostMapping
    public Result add(@RequestBody   WholeAsset wholeAsset){
        //调用WholeAssetService实现添加WholeAsset
        wholeAssetService.add(wholeAsset);
        return new Result(true,StatusCode.OK,"添加成功");
    }

    /***
     * 根据ID查询WholeAsset数据
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result<WholeAsset> findById(@PathVariable Long id){
        //调用WholeAssetService实现根据主键查询WholeAsset
        WholeAsset wholeAsset = wholeAssetService.findById(id);
        return new Result<WholeAsset>(true,StatusCode.OK,"查询成功",wholeAsset);
    }

    /***
     * 查询WholeAsset全部数据
     * @return
     */
    @GetMapping
    public Result<List<WholeAsset>> findAll(){
        //调用WholeAssetService实现查询所有WholeAsset
        List<WholeAsset> list = wholeAssetService.findAll();
        return new Result<List<WholeAsset>>(true, StatusCode.OK,"查询成功",list) ;
    }
}
